Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | 'use client'; import Image from 'next/image'; import type { ReactNode } from 'react'; import { AlertCircle, Edit, Play, Trash2, Wand2 } from 'lucide-react'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'; import { Tooltip } from '@/components/ui/tooltip'; import { TableSkeleton } from '@/components/ui/skeleton-loader'; import { Content, ContentListResponse, ContentType } from '@/types'; import type { CategoryConfig } from './config'; export type ContentTableProps = { isLoading: boolean; error: Error | null; isFetching: boolean; contentData?: ContentListResponse; currentCategory?: CategoryConfig; categoryActions?: ReactNode; yearFilter: string; filterActive: 'all' | 'active' | 'inactive'; providerFilter: string; countryFilter: string; selectedCategory: ContentType; selectedIds: number[]; setSelectedIds: (value: number[] | ((prev: number[]) => number[])) => void; onPreview: (content: Content) => void; onEnrich: (content: Content) => void; onEdit: (content: Content) => void; onDelete: (contentId: number) => void; isDeleting: boolean; typeColumnLabel: string; colDescription: boolean; colType: boolean; colStatus: boolean; colCreated: boolean; pageSize: number; setPageSize: (value: number) => void; setPage: (value: number | ((prev: number) => number)) => void; t: (key: string, options?: Record<string, any>) => string; i18nLanguage?: string; }; export default function ContentTable({ isLoading, error, isFetching, contentData, currentCategory, categoryActions, yearFilter, filterActive, providerFilter, countryFilter, selectedCategory, selectedIds, setSelectedIds, onPreview, onEnrich, onEdit, onDelete, isDeleting, typeColumnLabel, colDescription, colType, colStatus, colCreated, pageSize, setPageSize, setPage, t, i18nLanguage}: ContentTableProps) { if (isLoading) { return <TableSkeleton rows={10} columns={6} />; } if (error) { return ( <Alert variant="destructive"> <AlertCircle className="h-4 w-4" /> <AlertDescription> {t('content.errors.load', { message: error.message })} </AlertDescription> </Alert> ); } if (!contentData || contentData.total === 0) { return ( <div className="text-center py-8"> <div className="mx-auto mb-4 w-12 h-12 bg-gray-100 rounded-full flex items-center justify-center"> {currentCategory ? (() => { const Icon = currentCategory.icon; return <Icon className="h-6 w-6 text-gray-400" />; })() : null} </div> <h3 className="text-lg font-medium text-gray-900 mb-2">{t('content.empty.title')}</h3> <p className="text-gray-500 mb-4"> {t('content.empty.description', { category: currentCategory ? t(currentCategory.labelKey) : ''})} </p> {categoryActions ?? null} </div> ); } // Apply client-side filters (year, active) let items = contentData.content; if (yearFilter.trim()) { const y = parseInt(yearFilter.trim(), 10); if (!Number.isNaN(y)) { items = items.filter((it) => (it.year ?? 0) === y); } } if (filterActive !== 'all') { const needActive = filterActive === 'active'; items = items.filter((it) => it.active === needActive); } if (selectedCategory === ContentType.TV || selectedCategory === ContentType.EVENTS) { const p = providerFilter.trim().toLowerCase(); const c = countryFilter.trim().toLowerCase(); if (p) items = items.filter((it: any) => (it.provider || '').toLowerCase().includes(p)); if (c) items = items.filter((it: any) => (it.country || '').toLowerCase().includes(c)); } const totalItems = contentData.total; const currentPage = contentData.page; const currentLimit = contentData.limit; const safeLimit = currentLimit > 0 ? currentLimit : 1; const totalPages = Math.max(1, Math.ceil(totalItems / safeLimit)); const startIndex = (currentPage - 1) * currentLimit + 1; const endIndex = startIndex + items.length - 1; const canGoPrev = currentPage > 1; const canGoNext = currentPage < totalPages; const getTypeValue = (item: Content) => { switch (selectedCategory) { case ContentType.TV: return item.format || t('content.table.values.unknown'); case ContentType.EVENTS: return t('content.table.values.event'); default: return item.year || t('content.table.values.unknown'); } }; const formatCreatedAt = (value: string) => { const parsed = new Date(value); if (Number.isNaN(parsed.getTime())) { return '-'; } return parsed.toLocaleDateString(i18nLanguage || undefined, { year: 'numeric', month: 'short', day: 'numeric'}); }; return ( <div className="space-y-4"> <div className="overflow-x-auto"> <Table> <TableHeader className="sticky top-0 z-10 bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-200"> <TableRow> <TableHead className="w-12"> <input type="checkbox" checked={items.length > 0 && selectedIds.length === items.length} onChange={(e) => { if (e.target.checked) { setSelectedIds(items.map((it) => it.id)); } else { setSelectedIds([]); } }} aria-label={t('selectAll', {})} /> </TableHead> <TableHead className="min-w-[200px]">{t('content.table.columns.title')}</TableHead> {colDescription && (<TableHead className="min-w-[200px] max-w-[200px]">{t('content.table.columns.description')}</TableHead>)} {colType && (<TableHead className="min-w-[80px]">{typeColumnLabel}</TableHead>)} {colStatus && (<TableHead className="min-w-[100px]">{t('content.table.columns.status')}</TableHead>)} {colCreated && (<TableHead className="min-w-[100px]">{t('content.table.columns.created')}</TableHead>)} <TableHead className="min-w-[120px]">{t('content.table.columns.actions')}</TableHead> </TableRow> </TableHeader> <TableBody> {items.map((item) => ( <TableRow key={item.id}> <TableCell> <input type="checkbox" checked={selectedIds.includes(item.id)} onChange={() => { setSelectedIds((prev) => prev.includes(item.id) ? prev.filter((id) => id !== item.id) : [...prev, item.id] ); }} aria-label={`Select ${item.title}`} /> </TableCell> <TableCell> <div className="flex items-center gap-3"> {item.poster_url && ( <Image src={item.poster_url} alt={item.title} width={40} height={56} className="w-10 h-14 object-cover rounded" /> )} <div> <div className="font-medium flex items-center gap-1 flex-wrap"> <span className="truncate max-w-[250px]" title={item.title}>{item.title}</span> </div> {item.tmdb_id && ( <div className="text-sm text-gray-500">{t('content.table.values.tmdbId', { id: item.tmdb_id })}</div> )} </div> </div> </TableCell> {colDescription && ( <TableCell> <div className="max-w-[200px] truncate" title={item.description || ''}> {item.description ? item.description.length > 50 ? `${item.description.substring(0, 50)}...` : item.description : t('content.table.values.noDescription')} </div> </TableCell> )} {colType && (<TableCell>{getTypeValue(item)}</TableCell>)} {colStatus && ( <TableCell> <Badge variant="outline" className={item.active ? 'border-emerald-300 text-emerald-700 bg-emerald-50' : 'border-slate-300 text-slate-500 bg-slate-50'}> {item.active ? t('common.active') : t('common.inactive')} </Badge> </TableCell> )} {colCreated && ( <TableCell> {formatCreatedAt(item.created_at)} </TableCell> )} <TableCell> <div className="flex items-center gap-2"> {(selectedCategory === ContentType.VOD || selectedCategory === ContentType.KIDS || selectedCategory === ContentType.TV || selectedCategory === ContentType.EVENTS) && ( <Tooltip content={t('content.actions.preview', {})}> <Button variant="outline" size="sm" className="h-8 px-3 bg-white text-slate-700 border-slate-200" onClick={() => onPreview(item)}> <Play className="h-4 w-4" /> <span className="hidden xl:inline ml-1">{t('content.actions.preview', {})}</span> </Button> </Tooltip> )} {/* TMDB button - hide for Live TV since TMDB doesn't have TV channels */} {selectedCategory !== ContentType.TV && ( <Tooltip content={t('content.actions.enrichTmdb', {})}> <Button variant="outline" size="sm" className="h-8 px-3 bg-white text-blue-600 border-blue-200 hover:bg-blue-50" onClick={() => onEnrich(item)}> <Wand2 className="h-4 w-4" /> <span className="hidden xl:inline ml-1">{t('contentList.tmdb')}</span> </Button> </Tooltip> )} <Tooltip content={t('common.edit')}> <Button variant="outline" size="sm" className="h-8 px-3 bg-white text-slate-700 border-slate-200" onClick={() => onEdit(item)}> <Edit className="h-4 w-4" /> <span className="hidden xl:inline ml-1">{t('common.edit')}</span> </Button> </Tooltip> <Tooltip content={t('common.delete')}> <Button variant="destructive" size="sm" className="h-8 px-3" onClick={() => onDelete(item.id)} disabled={isDeleting}> <Trash2 className="h-4 w-4" /> <span className="hidden xl:inline ml-1">{t('common.delete')}</span> </Button> </Tooltip> </div> </TableCell> </TableRow> ))} </TableBody> </Table> </div> <div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between"> <div className="text-sm text-gray-600"> {t('content.pagination.range', { start: startIndex, end: endIndex, total: totalItems})} {isFetching ? ( <span className="ml-2 text-xs text-muted-foreground">{t('content.pagination.updating', {})}</span> ) : null} </div> <div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:gap-4"> <div className="flex items-center gap-2"> <span className="text-sm text-gray-600">{t('content.pagination.rowsPerPage', {})}</span> <Select value={String(pageSize)} onValueChange={(value) => { const newSize = Number(value); if (!Number.isNaN(newSize)) { setPageSize(newSize); setPage(1); } }} > <SelectTrigger size="sm" className="w-[90px]"> <SelectValue placeholder={t('content.pagination.rows', {})} /> </SelectTrigger> <SelectContent> {[10, 25, 50, 100].map((option) => ( <SelectItem key={option} value={String(option)}> {option} </SelectItem> ))} </SelectContent> </Select> </div> <div className="flex items-center gap-2"> <Button variant="outline" size="sm" onClick={() => setPage((prev) => Math.max(1, prev - 1))} disabled={!canGoPrev} > {t('common.previous')} </Button> <span className="text-sm text-gray-600"> {t('content.pagination.pageOf', { page: currentPage, total: totalPages})} </span> <Button variant="outline" size="sm" onClick={() => setPage((prev) => Math.min(totalPages, prev + 1))} disabled={!canGoNext} > {t('common.next')} </Button> </div> </div> </div> </div> ); } |